package main.java.person.fjsp;


import main.java.person.fjsp.algorithm.ga.entity.Individual;
import main.java.person.fjsp.algorithm.ga.utils.GAUtils;
import main.java.person.fjsp.algorithm.ha.HASolver;
import main.java.person.fjsp.common.entity.DataManager;
import main.java.person.fjsp.common.entity.Machine;
import main.java.person.fjsp.common.entity.ScheduleResult;
import main.java.person.fjsp.common.utils.ProcessDataUtils;

import java.util.Comparator;
//https://gitee.com/xcy-ghl/tradition_fjsp
public class Main {

    public static void main(String[] args) throws Exception {

        long beginTime = System.currentTimeMillis();
        String dataName="MK";
        String dataNumber = "06";
        String path="D:\\郭星的文件\\研究生\\浏览器下载\\参考文献\\tradition_fjsp-master\\tradition_fjsp-master\\data\\Monaldo\\Fjsp\\Job_Data\\Barnes\\Text\\mt10c1.fjs";
        DataManager dataManager = new ProcessDataUtils().readFileToJobList(path);
        GAUtils gaUtils = new GAUtils();
        HASolver haSolver = new HASolver(500, 150,  0.95, 0.1, 300, 10,0.05);
        haSolver.setMaxCalTime(360000L);
        Individual solve = haSolver.solve(dataManager);
        System.out.println("==========="+dataName+dataNumber+"=========");
        ScheduleResult scheduleResult = gaUtils.getScheduleResult(solve.getCsCode(), solve.getOsCode(), dataManager);
        gaUtils.checkScheduleResult(scheduleResult, dataManager);
        System.out.println("最大适应值：" + solve.getFitness());
        int completeTime = scheduleResult.getMachines().stream().max(Comparator.comparing(Machine::getCompleteTime)).orElseThrow().getCompleteTime();
        System.out.println("最大完工时间：" + completeTime);
        new ProcessDataUtils().writeSchedule("result/HA-"+dataName + dataNumber + ".txt", scheduleResult);
        System.out.println("计算时间"+(System.currentTimeMillis() - beginTime));


    }


}




